/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package cz.cuni.amis.episodic.bayes.utils;

import java.awt.Color;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStream;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.GregorianCalendar;
import org.jfree.chart.ChartFrame;

import org.jfree.chart.ChartUtilities;
import org.jfree.chart.JFreeChart;
import org.jfree.chart.axis.DateAxis;
import org.jfree.chart.axis.DateTickUnit;
import org.jfree.chart.axis.NumberAxis;
import org.jfree.chart.plot.XYPlot;
import org.jfree.chart.renderer.LookupPaintScale;
import org.jfree.chart.renderer.xy.XYBlockRenderer;
import org.jfree.data.time.Week;
import org.jfree.data.xy.DefaultXYZDataset;
import org.jfree.data.xy.XYDataset;

public class GraphDemoHack {
    public GraphDemoHack() {
       
    }
    private JFreeChart createChart(XYDataset dataset) {
      /*DateAxis xAxis = new DateAxis();
      DateFormat format = new SimpleDateFormat("MM/yy");
      DateTickUnit unit = new DateTickUnit(DateTickUnit.MONTH, 2, format);
      
      xAxis.setAutoRange(false);
      xAxis.setMaximumDate((Date)(dataset.getSeriesKey(dataset.getSeriesCount() - 1)));
      xAxis.setMinimumDate((Date)(dataset.getSeriesKey(1)));
      xAxis.setTickUnit(unit);
       */     
        NumberAxis xAxis = new NumberAxis("x Axis");
        
        NumberAxis yAxis = new NumberAxis("y Axis");

        XYBlockRenderer r = new XYBlockRenderer();
        LookupPaintScale ps = new LookupPaintScale(0,1001,Color.lightGray);
        ps.add(0,Color.RED);
        ps.add(101,new Color(255,128,0));
        ps.add(202,new Color(255,255,0));
        ps.add(303,new Color(192,255,0));
        ps.add(404,new Color(128,255,0));
        ps.add(505,new Color(0,255,0));
       
        r.setPaintScale(ps);
        //r.setBlockHeight(0.75f);
        //r.setBlockWidth(1.0f);  // OR 100.0f OR 1000.0f--no difference
        
        XYPlot plot = new XYPlot(dataset, xAxis, yAxis, r);
      JFreeChart chart = new JFreeChart("Chart Title",JFreeChart.DEFAULT_TITLE_FONT,plot,false);
        chart.setBackgroundPaint(Color.white);
        return chart;
    }
    
    private XYDataset createDataset() {
        DefaultXYZDataset dataset = new DefaultXYZDataset();
           int items = 100;
           for(int i=1;i<items;i++){
               GregorianCalendar gc = new GregorianCalendar(2005, 12, 30);
               gc.add(GregorianCalendar.DAY_OF_YEAR, i*7);
               double[][] data = new double[3][items];
                 for(int j=1;j<10;j++){
                  data[0][j-1]= gc.getTimeInMillis();
                  data[1][j-1]= j;
                  data[2][j-1]= i*j;
                 }
              dataset.addSeries(gc.getTime(),data);
           }
        return dataset;
    }
   
   
    /**
     * Starting point for the demonstration application.
     *
     * @param args  ignored.
     */
    public static void main(String[] args) {
       GraphDemoHack demo = new GraphDemoHack();
       
       JFreeChart chart = demo.createChart(demo.createDataset());
       
        ChartFrame frame = new ChartFrame("First", chart);
        frame.pack();
        frame.setVisible(true);
       
    } 

}